using CfgTable;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class UIChooseGift : UIBaseWindow
    {
        #region Template Generate,don't modify
        protected class UIB_UIChooseGift
        {
            #region ObjectBinding Generate
            public UnityEngine.GameObject heroPanel { protected set; get; }
            public UnityEngine.GameObject equipPanel { protected set; get; }
            public UnityEngine.GameObject itemPanel { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<UnityEngine.GameObject>("heroPanel", out var __tbv0);
                this.heroPanel = __tbv0;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("equipPanel", out var __tbv1);
                this.equipPanel = __tbv1;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("itemPanel", out var __tbv2);
                this.itemPanel = __tbv2;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region Window Config
        /// <summary>
        /// 静态配置
        /// </summary>
        private static UICreateConfig _createConfig = new()
        {
            prefabName = nameof(UIChooseGift),
            layer = EUILayer.Normal,
        };

        /// <summary>
        /// 创建UI的配置
        /// </summary>
        public override IUICreateConfig createConfig => _createConfig;
        #endregion Window Config

        #region fields
        private UIN_ChooseGiftItemPanel itemPanel;
        private UIN_ChooseGiftEquipPanel equipPanel;
        private UIN_ChooseGiftHeroPanel heroPanel;

        private ItemData itemData;
        private CfgSystemEffect cfgItemEffect;
        #endregion fields

        #region properties

        protected UIB_UIChooseGift ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIChooseGift();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.itemPanel = this.InitChildNode<UIN_ChooseGiftItemPanel>(this.ui.itemPanel);
            this.equipPanel = this.InitChildNode<UIN_ChooseGiftEquipPanel>(this.ui.equipPanel);
            this.heroPanel = this.InitChildNode<UIN_ChooseGiftHeroPanel>(this.ui.heroPanel);
        }

        protected override void OnShow(UIBaseData data)
        {
            this.SetData(data);
            this.ShowView();
        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {

        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }

        #region methonds

        private void SetData(object data)
        {
            this.itemData = (ItemData)data;
            this.cfgItemEffect = TableCenter.systemEffect.Get(itemData.cfgData.ItemEffectID);
        }

        private void ShowView()
        {
            switch ((EffectType)this.cfgItemEffect.Type)
            {
                case EffectType.GitChooseItem:
                    ShowChooseItem();
                    break;
                case EffectType.GitChooseEquip:
                    ShowChooseEquip();
                    break;
                case EffectType.GitChooseHero:
                    ShowChooseHero();
                    break;
                default:
                    break;
            }
        }

        private void ShowChooseItem()
        {
            this.itemPanel.Show(this.itemData);
        }

        private void ShowChooseEquip()
        {
            this.equipPanel.Show(this.itemData);
        }

        private void ShowChooseHero()
        {
            this.heroPanel.Show(this.itemData);
        }
        #endregion methonds
    }
}
